package com.cplh.sharding.demo.controller;


import com.cplh.zhdata.sharding.ds.DbShardingAlgorithm;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: kangzhijin
 * @since: 2022/10/12
 * @version: 1.0
 * @description:
 **/
@Slf4j
@RestController
@RequestMapping("/sharding")
public class ShardingAdminController {



    @GetMapping("/getDb/{projectId}")
    public String getDb(@PathVariable("projectId") String projectId) {

        int dbSharding = DbShardingAlgorithm.calcDbIndex(projectId);


        log.info("项目ID【" + projectId + "】 在DB 【" + dbSharding +  "】库.");
        return "项目ID【" + projectId + "】 在DB 【" + dbSharding +  "】库.";
    }



}
